<template>
  <div class="dashboard-container">
    <!--    <component :is="currentRole"/>-->
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import adminDashboard from "./admin";
import editorDashboard from "./editor";
import { queryUserInfo } from "@/api/system/user";

export default {
  name: "Dashboard",
  components: { adminDashboard, editorDashboard },
  data() {
    return {
      currentRole: "adminDashboard"
    };
  },
  computed: {
    ...mapGetters(["roles"])
  },
  created() {
    // if (!this.roles.includes('admin')) {
    //   this.currentRole = 'editorDashboard'
    // }
    //this.getUser()
  },
  methods: {
    getUser() {
      queryUserInfo().then(res => {
        const userDataResKey = res.data.dataResourceKey;
        const resList = res.data.res;
        if (userDataResKey) {
          if (userDataResKey === "300") {
            const permissionRoles = ["statistics5"];
            const hasPermission = resList.some(role => {
              return permissionRoles.includes(role);
            });
            if (!hasPermission) {
              alert("没有权限");
            } else {
              alert("跳转页面");
              this.$router.push({
                path: "/system/permission/performanceRank"
              });
            }
          } else if (userDataResKey === "200") {
            const permissionRoles = ["statistics5;"];
            const hasPermission = resList.some(role => {
              return permissionRoles.includes(role);
            });

            if (!hasPermission) {
              alert("没有权限");
            } else {
              alert("跳转页面");
              this.$router.push({
                path: "/system/permission/performanceRank"
              });
            }
          } else if (userDataResKey === "100") {
            const permissionRoles = ["clueTable"];
            const hasPermission = resList.some(role => {
              return permissionRoles.includes(role);
            });

            if (!hasPermission) {
              alert("没有权限");
            } else {
              alert("跳转页面");
              this.$router.push({
                path: "/system/permission/clueTable"
              });
            }
          } else {
          }
        } else {
          this.$message({
            message: "数据权限配置不正确！请联系管理员",
            type: "error"
          });
        }
      });
    }
  }
};
</script>
